<?php

namespace app\admin\controller\user_profile\userArchive;

use app\admin\service\user_profile\userArchive\UserArchiveService;
use app\BaseController;
use app\common\Message;
use think\App;
use think\response\Json;

class UserArchive extends BaseController
{
    use Message;

    /**
     * @var array|mixed
     */
    private mixed $data;
    private UserArchiveService $userArchiveService;

    public function __construct(App $app)
    {
        parent::__construct($app);
        $data = $this->request->param();
        $data['uid'] = $this->userData['id'];
        $data['role_mode'] = $this->userData['role_mode'];
        $data['unit_id'] = $this->userData['unit_id'];
        //单位id
        $data['platform_unit_id'] = $this->userData['unit_id'];
        $this->userArchiveService = new UserArchiveService($this->app);
        $this->data = $data;
    }

    /**
     * 获取档案列表
     * @return bool|string|Json
     */
    public function getList(): bool|string|Json
    {
        try {
            if(!$this->userArchiveService->getList($this->data)) throw new \Exception($this->userArchiveService->getMessage());
            return success($this->userArchiveService->getResult(),$this->userArchiveService->getMessage());
        } catch (\Exception $e) {
            return error($e->getMessage(),$e->getCode(),[
                'line' => $e->getLine(),
                'file' => $e->getFile()
            ]);
        }
    }

    /**
     * 获取查阅权限
     * @return bool|string|Json
     */
    public function getPermission(): bool|string|Json
    {
        try {
            if(!$this->userArchiveService->getPermission($this->data)) throw new \Exception($this->userArchiveService->getMessage());
            return success($this->userArchiveService->getResult(),$this->userArchiveService->getMessage());
        } catch (\Exception $e) {
            return error($e->getMessage(),$e->getCode(),[
                'line' => $e->getLine(),
                'file' => $e->getFile()
            ]);
        }
    }

    /**
     * 部门选择-树结构
     * @return bool|string|Json
     */
    public function getClass(): bool|string|Json
    {
        try {
            if(!$this->userArchiveService->getClass($this->data)) throw new \Exception($this->userArchiveService->getMessage());
            return success($this->userArchiveService->getResult(),$this->userArchiveService->getMessage());
        } catch (\Exception $e) {
            return error($e->getMessage(),$e->getCode(),[
                'line' => $e->getLine(),
                'file' => $e->getFile()
            ]);
        }
    }

    /**
     * 删除档案
     * @return bool|string
     */
    public function deleteRecode(): bool|string
    {
        try {
            if(!$this->userArchiveService->deleteRecode($this->data)) throw new \Exception($this->userArchiveService->getMessage());
            return success($this->userArchiveService->getResult(),$this->userArchiveService->getMessage());
        } catch (\Exception $e) {
            return error($e->getMessage(),$e->getCode(),[
                'line' => $e->getLine(),
                'file' => $e->getFile()
            ]);
        }
    }

    /**
     * 验证废除档案是否有之前废弃的，【0：有，1：没有】
     * @return bool|string
     */
    public function checkRepealArchive(): bool|string
    {
        try {
            if(!$this->userArchiveService->checkRepealArchive($this->data)) throw new \Exception($this->userArchiveService->getMessage());
            return success($this->userArchiveService->getResult(),$this->userArchiveService->getMessage());
        } catch (\Exception $e) {
            return error($e->getMessage(),$e->getCode(),[
                'line' => $e->getLine(),
                'file' => $e->getFile()
            ]);
        }
    }

    /**
     * 是否显示档案
     * @return bool|string
     */
    public function isShow(): bool|string
    {
        try {
            if(!$this->userArchiveService->isShow($this->data)) throw new \Exception($this->userArchiveService->getMessage());
            return success($this->userArchiveService->getResult(),$this->userArchiveService->getMessage());
        } catch (\Exception $e) {
            return error($e->getMessage(),$e->getCode(),[
                'line' => $e->getLine(),
                'file' => $e->getFile()
            ]);
        }
    }


}